import Docxtemplater from 'docxtemplater';
import PizZip from 'pizzip';


// 读取模板文件
const template = await fetch('../../public/pay-modules.docx');
const arrayBuffer = await template.arrayBuffer();

// 处理模板
const zip = new PizZip(arrayBuffer);
const doc = new Docxtemplater(zip, {
  paragraphLoop: true,
  linebreaks: true,
});

// 设置数据
doc.setData({
  name: "张三",
  age: 25,
  items: [
    { name: "项目1", value: "值1" },
    { name: "项目2", value: "值2" }
  ]
});

// 渲染并生成
doc.render();
const out = doc.getZip().generate({
  type: "blob",
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
});

// 下载
const link = document.createElement('a');
link.href = URL.createObjectURL(out);
link.download = 'output.docx';
link.click();
